package tasks.task03;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;


public class easytask03 {
    public static void main(String[] args) {

        try {
            DocumentBuilderFactory build = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = build.newDocumentBuilder();
            Document doc = db.parse("exml.xml");
            doc.getDocumentElement().normalize();

            Element root = doc.getDocumentElement();
            NodeList a = root.getChildNodes();

            for (int s = 0; s < a.getLength(); s++) {
                Node firstXmlNode = a.item(s);
                if (firstXmlNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element firstXmlElement = (Element) firstXmlNode;

                    System.out.println(firstXmlElement.getTagName() + ", " + firstXmlElement.getAttribute("text"));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


